import DictionConstUtil from '@/utils/diction-const-util';
import { dateFormat, numberFormat, objToVxeFilterArr, PrefixInteger, timeFormat, unitShow } from '@/utils/tools';
import { Vue } from 'vue-property-decorator';
import * as moment from 'moment';
import Invest from '@/common/dict/invest';
import ColumnUtil from '@/pages/risk-time/utils/column-util';

export default class InstructionColumnUtil extends Vue {
    invest = new Invest();
    ColumnUtil = new ColumnUtil();
    tableColumn = [
        {
            content: '恒生指令序号',
            id: 'dailyInstructionNo',
            minWidth: 160,
        },
        {
            content: '指令序号',
            id: 'instructionNo',
            minWidth: 120,
        },
        { content: '指令批号', id: 'batchNo', minWidth: 120 },
        {
            content: '产品代码',
            id: 'fundCode',
            minWidth: 120,
            // type:'func',
            // funcBody: async value => (await DictionConstUtil.FNFundShowCode)(value),
        },
        {
            content: '数据来源',
            id: 'sourceType',
            minWidth: 120,
            type: 'func',
            funcBody: value => DictionConstUtil.SourceType[value],
        },
        {
            content: '产品名称',
            id: 'fundNameSt',
            minWidth: 120,
        },
        {
            content: '组合编码',
            id: 'fundAccountCode',
            minWidth: 130,
        },
        {
            content: '组合名称',
            id: 'fundAccountName',
            minWidth: 130,
        },
        {
            content: '证券代码',
            id: 'stockCode',
            minWidth: 120,
        },
        {
            content: '证券名称',
            id: 'stockName',
            minWidth: 120,
        },
        {
            content: '证券类别',
            id: 'stockType',
            minWidth: 120,
            // type:'func',
            // funcBody:(value)=>(this.stockTypeAll.find(item => item.dictKey == value) || {}).dictKeyName
        },
        {
            content: '业务类型',
            id: 'businessTypeName',
            minWidth: 120,
        },
        {
            content: '委托方向',
            id: 'orderDirection',
            minWidth: 120,
        },
        {
            content: '投资类型',
            id: 'investType',
            minWidth: 120,
        },
        { content: '转入组合编码', id: 'destCombiId', minWidth: 140 },
        { content: '转入组合名称', id: 'destCombiName', minWidth: 140 },
        { content: '转入证券代码', id: 'destSecurityCode', minWidth: 140 },
        { content: '转入证券名称', id: 'destSecurityName', minWidth: 140 },
        { content: '转入投资类型', id: 'intoInvestType', minWidth: 140 },
        { content: '巨额赎回', id: 'bulkType', minWidth: 120 },
        {
            content: '币种',
            id: 'curCode',
            minWidth: 90,
        },
        {
            content: '交易市场',
            id: 'marketName',
            minWidth: 120,
        },
        {
            content: '下达时间',
            id: 'directTime',
            minWidth: 160,
            type: 'func',
            funcBody: (value, row) => (dateFormat(row.directDate) + ' ' + timeFormat(row.directTime)).trim(),
        },
        {
            content: '下达人',
            id: 'directUserName',
            minWidth: 120,
        },
        {
            content: '指令状态',
            id: 'instStatus',
            minWidth: 120,
            type: 'func',
            funcBody: value => DictionConstUtil.instStatusType[value],
        },
    ];
    get tableColumns() {
        return this.ColumnUtil.handleTableColumns(this.tableColumn, 'id');
    }

    instStockColumn = [
        {
            name: '指令序号',
            val: 'instNo',
            minWidth: 100,
        },
        // 与其他指令证券的区别,多了个指令批号
        { name: '指令批号', val: 'batchNo', minWidth: 120 },
        {
            name: '产品代码',
            val: 'fundCode',
            minWidth: 100,
            // type: 'func',
            // funcBody: (value) => DictionConstUtil.FNFundShowCode(value)
        },
        {
            name: '产品名称',
            val: 'fundNameSt',
            minWidth: 100,
        },
        {
            name: '组合编码',
            val: 'fdAcCode',
            minWidth: 120,
        },
        {
            name: '组合名称',
            val: 'fdAcName',
            minWidth: 120,
        },
        {
            name: '证券代码',
            val: 'stockCode',
            minWidth: 130,
        },
        {
            name: '证券名称',
            val: 'stockNameSt',
            minWidth: 120,
        },

        { name: '转入组合编码', val: 'destCombiId', minWidth: 150 },
        { name: '转入组合名称', val: 'destCombiName', minWidth: 150 },
        { name: '转入证券代码', val: 'destSecurityCode', minWidth: 120 },
        { name: '转入证券名称', val: 'destSecurityName', minWidth: 120 },
        {
            name: '转入投资类型',
            val: 'investType',
            minWidth: 120,
            type: 'func',
            funcBody: value => (value ? this.invest.investType[value] : '--'),
        },
        { name: '巨额赎回', val: 'bulkType', minWidth: 120, type: 'func', funcBody: value => (value ? this.invest.bulkType[value] : '--') },
        {
            name: '委托方向',
            val: 'realDirection',
            minWidth: 120,
        },
        {
            name: '交易市场',
            val: 'marketName',
            minWidth: 100,
        },
        {
            name: '投资类型',
            val: 'investType',
            minWidth: 100,
            type: 'func',
            funcBody: value => this.invest.investType[value],
        },
        {
            name: '指令数量',
            val: 'instAmount',
            minWidth: 100,
            type: 'funcNumber',
            funcBody: value => numberFormat(value, 2) || '--',
        },
        {
            name: '指令价格',
            val: 'instPrice',
            minWidth: 100,
            type: 'funcNumber',
            funcBody: value => numberFormat(value, 2) || '--',
        },
        {
            name: '指令金额',
            val: 'instBalance',
            minWidth: 100,
            type: 'funcNumber',
            funcBody: value => numberFormat(value, 2) || '--',
        },
        {
            name: '交割日',
            val: 'deliveryDate',
            minWidth: 100,
            type: 'func',
            funcBody: value => dateFormat(value) || '--',
        },
        {
            name: '回购日期',
            val: 'repoDate',
            minWidth: 100,
            type: 'func',
            funcBody: value => dateFormat(value) || '--',
        },
        {
            name: '回购天数',
            val: 'repoDay',
            minWidth: 100,
        },
        {
            name: '回购到期日',
            val: 'repurDate',
            minWidth: 100,
            type: 'func',
            funcBody: value => dateFormat(value),
        },
        {
            name: '存款类型',
            val: 'depositType',
            minWidth: 100,
            type: 'func',
            funcBody: value => this.invest.depositType[value],
        },
        {
            name: '存款利率',
            val: 'reate',
            minWidth: 100,
            type: 'funcNumber',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '存款期限（天）',
            val: 'poDayTerm',
            minWidth: 120,
        },
        {
            name: '银行总行代码',
            val: 'bankCode',
            minWidth: 130,
        },
        {
            name: '银行总行名称',
            val: 'bankNameSt',
            minWidth: 130,
        },
        {
            name: '提前支取类型',
            val: 'advanceType',
            minWidth: 130,
            type: 'func',
            funcBody: value => this.invest.advanceLimitFlag[value],
        },
    ];

    get instStockColumns() {
        return this.ColumnUtil.handleTableColumns(this.instStockColumn, 'val');
    }

    // 默认的指令明细字段
    defaultDetailColumn = [
        {
            name: '指令序号',
            val: 'instructionNo',
        },
        { name: '指令批号', val: 'batchNo', minWidth: 120 },

        {
            name: '指令状态',
            val: 'instStatus',
            type: 'func',
            funcBody: value => DictionConstUtil.instStatusType[value],
        },
        {
            name: '下达人',
            val: 'directUserName',
            type: 'func',
            funcBody: (value, row) => row.directUserName || '--',
        },
        {
            name: '下达时间',
            val: 'directDT',
            type: 'func',
            funcBody: (value, row) => (dateFormat(row.directDate) + ' ' + timeFormat(row.directTime)).trim() || '--',
        },
        {
            name: '指令价格(元)',
            val: 'instPrice',
            type: 'func',
            funcBody: value => numberFormat(value, 4) || '--',
        },
        {
            name: '指令数量(张)',
            val: 'instAmount',
            type: 'func',
            funcBody: value => numberFormat(value, 2) || '--',
        },
        {
            name: ' 指令金额(元)',
            val: 'instBalance',
            type: 'func',
            funcBody: value => numberFormat(value, 2) || '--',
        },
        {
            name: '产品代码',
            val: 'fundCode',
        },
        {
            name: '产品名称',
            val: 'fundNameSt',
        },
        {
            name: '组合编码',
            val: 'fundAccountCode',
        },
        {
            name: '组合名称',
            val: 'fundAccountName',
        },
        {
            name: '证券代码',
            val: 'stockCode',
        },
        {
            name: '证券名称',
            val: 'stockName',
        },
        {
            name: '证券类别',
            val: 'stockType',
        },
        {
            name: '投资类型',
            val: 'investType',
        },
        {
            name: '业务类型',
            val: 'businessTypeName',
        },
        {
            name: '委托方向',
            val: 'orderDirection',
        },
        {
            name: '币种',
            val: 'curName',
        },
        {
            name: '交易市场',
            val: 'marketName',
        },
        {
            name: '数据来源',
            val: 'sourceType',
            type: 'func',
            funcBody: value => DictionConstUtil.SourceType[value],
        },
    ];

    otherBankBondFields = [
        {
            name: '券面总额(万元)',
            val: 'faceTotalBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, '万元') : '--'),
        },
        {
            name: '净价价格(元)',
            val: 'netPrice',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '全价价格(元)',
            val: 'fullPrice',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: ' 净价金额(元)',
            val: 'netBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '清算速度',
            val: 'clearSpeed',
            type: 'func',
            funcBody: value => (value ? 'T+' + value : 'T+0'),
        },
        {
            name: '结算日期',
            val: 'settleDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '指令数量(张)',
            val: 'instAmount',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '结算金额(元)',
            val: 'settleBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
    ];

    otherPrimaryBondFields = [
        {
            name: '投标日期',
            val: 'bidStartDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '投标截止日期',
            val: 'bidEndDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '缴款日期',
            val: 'payDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '上市日期',
            val: 'listDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '发行规模(亿)',
            val: 'totalBalance',
            type: 'func',
            funcBody: value => numberFormat(value, '亿元') || '--',
        },
        {
            name: '债券类别',
            val: 'bondType',
            // type: 'func',
            // funcBody: value => (value ? this.getBondType(value) : '--'),
        },
        {
            name: '发行人',
            val: 'issueName',
        },
        {
            name: '发行人性质',
            val: 'issuerNature',
        },
        {
            name: '信用评级(主体/债券)',
            val: 'grade',
            type: 'func',
            funcBody: (value, row) => row.issueGrade + '/' + row.bondGrade,
        },
    ];
    otherDepositFields = [
        {
            name: '存款类型',
            val: 'depositType',
            type: 'func',
            funcBody: value => this.invest.depositType[value] || '--',
        },
        {
            name: '通知天数(天)',
            val: 'noticeDay',
        },
        {
            name: '支取类型',
            val: 'advanceType',
            type: 'func',
            funcBody: value => this.invest.advanceLimitFlag[value],
        },
        {
            name: '银行总行代码',
            val: 'bankCode',
        },
        {
            name: '银行总行名称',
            val: 'bankName',
        },
        {
            name: '起息日',
            val: 'startExtraDay',
            type: 'func',
            funcBody: (value, row) =>
                moment(row.dueDate)
                    .subtract(row.depositTerm, 'days')
                    .format('YYYY-MM-DD'),
        },
        {
            name: '到期日期',
            val: 'dueDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '存款期限(天)',
            val: 'depositTerm',
        },
        {
            name: '存款金额(元)',
            val: 'depositBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '存款利率(%)',
            val: 'depositRate',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '存款利息(元)',
            val: 'depositInterest',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '到期金额(元)',
            val: 'dueBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
    ];
    otherBankHgFields = [
        {
            name: '回购金额',
            val: 'repoBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '回购天数',
            val: 'repoDay',
        },
        {
            name: '实际占款天数',
            val: 'actualDay',
            type: 'func',
            funcBody: (value, row) => moment(row.secondSettleDate).diff(row.firstSettleDate, 'day'),
        },
        {
            name: '首次结算日期',
            val: 'firstSettleDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '到期结算日期',
            val: 'secondSettleDate',
            type: 'func',
            funcBody: value => (value ? dateFormat(value, true) : '--'),
        },
        {
            name: '清算速度',
            val: 'clearSpeed',
            type: 'func',
            funcBody: value => (value ? 'T+' + value : 'T+0'),
        },
        {
            name: '回购利率(%)',
            val: 'repoRate',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '应计利息',
            val: 'tDayInterest',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '到期回购金额',
            val: 'dueRepoBalance',
            type: 'func',
            funcBody: value => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '交易对手',
            val: 'opponentName',
        },
    ];
    otherCWOpenFields = [
        { name: '转入组合编码', val: 'destCombiId', minWidth: 150 },
        { name: '转入组合名称', val: 'destCombiName', minWidth: 150 },
        { name: '转入证券代码', val: 'destSecurityCode', minWidth: 120 },
        { name: '转入证券名称', val: 'destSecurityName', minWidth: 120 },
        {
            name: '转入投资类型',
            val: 'investType',
            type: 'func',
            funcBody: (value, row) => (row['orderDirection'] === '基金转换' ? row.investType || '--' : '--'),
        },
        { name: '巨额赎回', val: 'bulkType', minWidth: 120, type: 'func', funcBody: value => this.invest.bulkType[value] },
    ];

    /**
     * ETF指令信息表格字段
     */
    /**
     * ETF指令信息表格字段
     */
    ETFOrderInfoColumns: any[] = [
        // { name: '指令序号', val: 'instNo', minWidth: 120, fixed: 'left' },
        // {
        //     name: '指令状态',
        //     val: 'instStatus',
        //     minWidth: 120,
        //     fixed: 'right',
        //     type: 'func',
        //     funcBody: value => DictionConstUtil.instStatusType[value],
        // },
        // { name: '产品代码', val: 'fundCode', minWidth: 120, fixed: 'left' },
        // { name: '产品名称', val: 'fundName', minWidth: 120 },
        // { name: '组合编码', val: 'groupCode', minWidth: 150 },
        // { name: '组合名称', val: 'groupName', minWidth: 150 },
        // { name: '证券代码', val: 'stockCode', minWidth: 120 },
        // { name: '证券名称', val: 'stockName', minWidth: 120 },
        // { name: '证券类别', val: 'stockType', minWidth: 120 },
        // { name: '业务类型', val: 'businessTypeName', minWidth: 120 },
        // { name: '委托方向', val: 'orderDirectionName', minWidth: 120 },
        // { name: '投资类型', val: 'investTypeName', minWidth: 120 },
        // { name: '币种', val: 'curName', minWidth: 120 },
        // { name: '交易市场', val: 'marketName', minWidth: 120 },
        // { name: '指令价格(元)', val: 'orderPrice', minWidth: 140, type: 'func', funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--') },
        // { name: '指令数量(篮)', val: 'orderAmount', minWidth: 140, type: 'func', funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--') },
        // { name: '指令金额(元)', val: 'orderBalance', minWidth: 140, type: 'func', funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--') },
        {
            name: 'T日预估现金差额(元)',
            val: 'estimatecash',
            minWidth: 200,
            type: 'func',
            funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: 'T日预估现金差额汇总(元)',
            val: 'totalEstimatecash',
            minWidth: 220,
            type: 'func',
            funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--'),
        },
        {
            name: '现金替代总金额(元)',
            val: 'totalAlternativeAmount',
            minWidth: 200,
            type: 'func',
            funcBody: (value, row) => (value != undefined ? numberFormat(value, 2) : '--'),
        },
    ];
}
